package com.bili.bili_data_api.service.impl;

import com.bili.bili_data_api.dao.mapper.FanjuMapper;
import com.bili.bili_data_api.dao.mapper.GuochanMapper;
import com.bili.bili_data_api.dao.mapper.NumMapper;
import com.bili.bili_data_api.dao.pojo.bangumi;
import com.bili.bili_data_api.dao.pojo.Guochan;
import com.bili.bili_data_api.dao.pojo.Num;
import com.bili.bili_data_api.service.GRcompareService;
import com.bili.bili_data_api.vo.BeforTenVo;
import com.bili.bili_data_api.vo.NumVo;
import com.bili.bili_data_api.vo.Over;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class GRcompareServiceImpl implements GRcompareService {

    @Autowired
    private NumMapper numMapper;

    @Autowired
    private GuochanMapper guochanMapper;

    @Autowired
    private FanjuMapper fanjuMapper;

    @Override
    public NumVo score() {
        List<Num> nums = numMapper.selectList(null);
        NumVo numVo = new NumVo();
        List<String> scoreInterval=new ArrayList<>();
        List<String> GuoScoreNum=new ArrayList<>();
        List<String> RiScoreNum=new ArrayList<>();
        List<String> GuoMilionBilion=new ArrayList<>();
        List<String> RiMilionBilion=new ArrayList<>();
        List<Over> overs=new ArrayList<>();
        scoreInterval.add("<50万");
        scoreInterval.add("50万~100万");
        scoreInterval.add("100万~150万");
        scoreInterval.add(">150万");
        int i=0;
        for (Num num : nums) {
            if(i==0){
                Over over=new Over();
                GuoScoreNum.add(num.getLt50W());
                GuoScoreNum.add(num.getGt50Wlt100W());
                GuoScoreNum.add(num.getGt100Wlt150W());
                GuoScoreNum.add(num.getGt150W());
                numVo.setGuoScoreNum(GuoScoreNum);

                GuoMilionBilion.add(num.getKW());
                GuoMilionBilion.add(num.getWW());
                numVo.setGuoMilionBilion(GuoMilionBilion);

                over.setName("国产动画");
                over.setValue(num.getOver());
                overs.add(over);
                i++;
            }else {
                Over over=new Over();
                RiScoreNum.add(num.getLt50W());
                RiScoreNum.add(num.getGt50Wlt100W());
                RiScoreNum.add(num.getGt100Wlt150W());
                RiScoreNum.add(num.getGt150W());
                numVo.setRiScoreNum(RiScoreNum);

                RiMilionBilion.add(num.getKW());
                RiMilionBilion.add(num.getWW());
                numVo.setRiMilionBilion(RiMilionBilion);

                over.setName("番剧");
                over.setValue(num.getOver());
                overs.add(over);
            }

        }
        numVo.setScoreInterval(scoreInterval);
        numVo.setRiScoreNum(RiScoreNum);
        numVo.setOvers(overs);
        return numVo;
    }

    @Override
    public BeforTenVo guoBeforeTen() {
        List<Guochan> guochans = guochanMapper.selectList(null);
        BeforTenVo beforTenVo=new BeforTenVo();
        List<String> name=new ArrayList<>();
        List<String> views=new ArrayList<>();
        List<String> fan=new ArrayList<>();
        List<String> comment=new ArrayList<>();
        for (Guochan guochan : guochans) {
            if(guochan.getId()==11){
                break;
            }
            name.add(guochan.getTitle());
            char c= guochan.getViews().charAt(guochan.getViews().length()-1);
            if(c=='万'){
                views.add(String.valueOf(Float.valueOf(guochan.getViews().substring(0,guochan.getViews().length()-1))));
            }else if(c=='亿'){
                views.add(String.valueOf(Float.valueOf(guochan.getViews().substring(0,guochan.getViews().length()-1))*10000));
            }

            c= guochan.getFan().charAt(guochan.getFan().length()-1);
            if(c=='万'){
                fan.add(String.valueOf(Float.valueOf(guochan.getFan().substring(0,guochan.getFan().length()-1))));
            }else {
                fan.add(String.valueOf(Float.valueOf(guochan.getFan())));
            }

            c= guochan.getComment().charAt(guochan.getComment().length()-1);
            if(c=='万'){
                comment.add(String.valueOf(Float.valueOf(guochan.getComment().substring(0,guochan.getComment().length()-1))));
            }else {
                comment.add(String.valueOf(Float.valueOf(guochan.getComment())*0.0001).substring(0,6));
            }

        }
        beforTenVo.setName(name);
        beforTenVo.setComment(comment);
        beforTenVo.setFan(fan);
        beforTenVo.setViews(views);
        return beforTenVo;
    }

    @Override
    public BeforTenVo fanJuBeforeTen() {
        List<bangumi> fanjus = fanjuMapper.selectList(null);
        BeforTenVo beforTenVo=new BeforTenVo();
        List<String> name=new ArrayList<>();
        List<String> views=new ArrayList<>();
        List<String> fan=new ArrayList<>();
        List<String> comment=new ArrayList<>();
        for (bangumi fanju : fanjus) {
            if(fanju.getId()==11){
                break;
            }
            name.add(fanju.getTitle());
            char c= fanju.getViews().charAt(fanju.getViews().length()-1);
            if(c=='万'){
                views.add(String.valueOf(Float.valueOf(fanju.getViews().substring(0,fanju.getViews().length()-1))));
            }else if(c=='亿'){
                views.add(String.valueOf(Float.valueOf(fanju.getViews().substring(0,fanju.getViews().length()-1))*10000));
            }

            c= fanju.getFan().charAt(fanju.getFan().length()-1);
            if(c=='万'){
                fan.add(String.valueOf(Float.valueOf(fanju.getFan().substring(0,fanju.getFan().length()-1))));
            }else {
                fan.add(String.valueOf(Float.valueOf(fanju.getFan())));
            }

            c= fanju.getComment().charAt(fanju.getComment().length()-1);
            if(c=='万'){
                comment.add(String.valueOf(Float.valueOf(fanju.getComment().substring(0,fanju.getComment().length()-1))));
            }else {
                comment.add(String.valueOf(Float.valueOf(fanju.getComment())*0.0001).substring(0,6));
            }

        }
        beforTenVo.setName(name);
        beforTenVo.setComment(comment);
        beforTenVo.setFan(fan);
        beforTenVo.setViews(views);
        return beforTenVo;
    }
}
